//
//  TestEmptyViewController.swift
//  ADKit_Example
//
//  Created by Adoma on 2024/4/19.
//  Copyright © 2024 CocoaPods. All rights reserved.
//

import UIKit
import ADKit

class TestEmptyViewController: UIViewController {
    
    var count = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = count.toString
        view.backgroundColor = .random
        ADLogger(category: "TestEmptyViewController").log(level: .debug, #function)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        ADLogger(category: "TestEmptyViewController").log(level: .debug, #function)
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        ADLogger(category: "TestEmptyViewController").log(level: .debug, #function)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        ADLogger(category: "TestEmptyViewController").log(level: .debug, #function)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        print(#function, self.isMovingFromParentViewController, self.title)
    }
    
    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        print(#function, self.isMovingFromParentViewController, self.title)
    }
    
    deinit {
        print(#function, self.isMovingFromParentViewController, self.title)
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let count = count + 1
        if count == 3 {
           let vcs = self.navigationController?.viewControllers.filter { vc in
                if let vc = vc as? TestEmptyViewController, vc.count == 0 {
                    return false
                }
                return true
            } ?? []
            self.navigationController?.setViewControllers(vcs, animated: true)
            return
        }
        let controller = TestEmptyViewController()
        controller.count = count
        self.navigationController?.pushViewController(controller, animated: true)
    }
}
